package com.eduhzy.ttw.work.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.commonsdk.utils.MediaFile;
import com.eduhzy.ttw.work.R;
import com.eduhzy.ttw.work.mvp.model.entity.WorkDetailData;

import java.util.List;

/**
 * @author xubo
 * @date 2018/11/30 14:10
 */
public class WorkFileAdapter extends BaseQuickAdapter<WorkDetailData.FileListBean, AutoBaseViewHolder> {
    public WorkFileAdapter(@Nullable List<WorkDetailData.FileListBean> data) {
        super(R.layout.work_rv_item_file, data);
    }

    @Override
    protected void convert(AutoBaseViewHolder helper, WorkDetailData.FileListBean item) {
        ImageView imageView = (ImageView) helper.getView(R.id.iv_icon);
        String mimeTypeForFile = MediaFile.getMimeTypeForFile(item.getName());
        int fileTypeForMimeType = MediaFile.getFileTypeForMimeType(mimeTypeForFile);
        Glide.with(mContext)
                .load(item.getPreimage())
                .apply(RequestOptions.placeholderOf(MediaFile.isAudioFileType(fileTypeForMimeType) ? R.drawable.img_music : R.drawable.public_img_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                .into(imageView);

        if (MediaFile.isAudioFileType(fileTypeForMimeType)) {
            helper.setGone(R.id.btn_play, false);
        } else if (MediaFile.isVideoFileType(fileTypeForMimeType)) {
            helper.setGone(R.id.btn_play, true);
            helper.setBackgroundRes(R.id.btn_play, R.drawable.icon_bofang);
        } else if (MediaFile.isImageFileType(fileTypeForMimeType)) {
            helper.setGone(R.id.btn_play, false);
        }


    }
}
